#include "main.h"
#include "gpio.h"
#include "time.h"
#include "rtthread.h"
#include "shell.h"

rt_thread_t led_thread;



void led_entry(void *p)
{
    while (1)
    {
        HAL_GPIO_TogglePin(LED_D1_GPIO_Port, LED_D1_Pin);
        rt_thread_delay(50);
    }
}

int LED_INIT()
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    /* GPIO Ports Clock Enable */
    __HAL_RCC_GPIOC_CLK_ENABLE();

    /*Configure GPIO pin Output Level */
    HAL_GPIO_WritePin(GPIOC, LED_D2_Pin | LED_D1_Pin, GPIO_PIN_RESET);

    /*Configure GPIO pins : PCPin PCPin */
    GPIO_InitStruct.Pin = LED_D2_Pin | LED_D1_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
INIT_BOARD_EXPORT(LED_INIT);

void LED_ON()
{
    HAL_GPIO_WritePin(GPIOC, LED_D2_Pin, GPIO_PIN_RESET);
}
MSH_CMD_EXPORT(LED_ON, led open);

void LED_OFF()
{
    HAL_GPIO_WritePin(GPIOC, LED_D2_Pin, GPIO_PIN_SET);
}
MSH_CMD_EXPORT(LED_OFF, led close);

int main()
{
    //finsh_system_init();
    //LED_INIT();

    led_thread = rt_thread_create("LED", led_entry, NULL, 256, 5, 5);

    if (led_thread != RT_NULL)
    {
        rt_thread_startup(led_thread);
    }

    while (1)
    {
        rt_thread_delay(50);
    }
    return 0;
}
